﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Maticsoft.Common;
using CustomsSystem.BLL;
using CustomsSystem.Model;
using System.Data;

namespace WEB.WorkDate
{
    public partial class WorkDateset : System.Web.UI.Page
    {
        CustomsSystem.BLL.info_holiday bll = new CustomsSystem.BLL.info_holiday();
        CustomsSystem.Model.holiday model = new CustomsSystem.Model.holiday();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                DataSet ds = bll.GetList(" holidayS LIKE '" + cdDateset.TodaysDate.Year + "%' order by holidayS");
                
                lbDate.DataSource = ds;
                lbDate.DataValueField = "holidayID";
                lbDate.DataTextField = "holidayS";
                lbDate.DataBind();//绑定数据

                lbYear.Text = cdDateset.TodaysDate.Year.ToString();//显示年份
            }
        }

        protected void btSign_Click(object sender, EventArgs e)
        {
            if (cdDateset.SelectedDate.Year > 1)
            {
                if (lbDate.Items.FindByText(cdDateset.SelectedDate.ToString("yyyy-MM-dd")) == null)
                {
                    lbDate.Items.Add(cdDateset.SelectedDate.ToString("yyyy-MM-dd"));//增加日期
                    model.holidayS = cdDateset.SelectedDate.ToString("yyyy-MM-dd");
                   
                    bll.Add(model);//存储数据
                    DataSet ds = bll.GetList(" holidayS LIKE '" + cdDateset.SelectedDate.Year + "%' order by holidayS");
                    
                    lbDate.Items.Clear();//请空数据
                    lbDate.DataSource = ds;
                    lbDate.DataValueField = "holidayID";
                    lbDate.DataTextField = "holidayS";
                    lbDate.DataBind();//绑定数据

                }
                else
                {
                    MessageBox.Show(this, "不允许重复添加日期！");
                }
            }
            else
            { MessageBox.Show(this,"请选择日期！");}

        }

        protected void btDel_Click(object sender, EventArgs e)
        {
            if (lbDate.SelectedItem != null)
            {
                bll.Delete(lbDate.SelectedItem.ToString());
                lbDate.Items.Remove(lbDate.SelectedItem);
            }

            else { MessageBox.Show(this, "没有选中的列！"); }

        }

       
        protected void cdDateset_VisibleMonthChanged(object sender, MonthChangedEventArgs e)
        {
            if (!lbYear.Text.Equals(cdDateset.VisibleDate.Year.ToString()))
            {
                DataSet ds = bll.GetList(" holidayS LIKE '" + cdDateset.VisibleDate.Year + "%' order by holidayS");
                
                lbDate.Items.Clear();//请空数据
                lbDate.DataSource = ds.Tables[0];
                lbDate.DataValueField = "holidayID";
                lbDate.DataTextField = "holidayS";
                lbDate.DataBind();//绑定数据

                lbYear.Text = cdDateset.VisibleDate.Year.ToString();//显示年份
            }

        }

        protected void btReturn_Click(object sender, EventArgs e)
        {
            Response.Redirect("../Code/codeIndex.aspx");
        }
    }
}